package com.ai.chat.controller;

import com.ai.chat.domain.base.BaseAgentConfig;
import com.ai.chat.domain.base.request.BaseChatRequest;
import com.ai.chat.service.McpService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/mcp")
public class McpController {
    @Resource
    private McpService mcpService;

    @GetMapping("/config")
    public BaseAgentConfig config() {
        BaseAgentConfig config = new BaseAgentConfig();
        config.setName("mcp");
        config.setPrompt("我是你的AI智能助理，你可以问我任何问题");
        config.setStreamFlag(true);
        config.setNetQueryFlag(true);
        config.setAttachFlag(false);
        config.setDeepThinkFlag(true);
        config.setMultipleAgentFlag(false);
        config.setHistoryFlag(false);
        return config;
    }

    @PostMapping("/chat")
    public String chat(@RequestBody BaseChatRequest request) {
        return mcpService.chat(request);
    }

    @PostMapping("/streamChat")
    public Flux<String> streamChat(@RequestBody BaseChatRequest request, HttpServletResponse response) {
        return mcpService.streamChat(request, response);
    }

    @DeleteMapping("/streamChat")
    public void disposeStream(String streamId) {
        mcpService.disposeStream(streamId);
    }
}
